package com.sam.im.heiqun.uis.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sam.im.heiqun.R;
import com.sam.im.heiqun.entities.ImFriendEntivity;
import com.sam.im.heiqun.uis.adapters.holder.BlackFriendHolder;
import com.yuyh.library.utils.GlideUtils;

import java.util.List;

/**
 * Created by wangguodong on 2017/1/8.
 * 通讯录使用
 *
 */

public class BlackFriendAdpter extends RecyclerView.Adapter<BlackFriendHolder> {

    private Context context;
    private List<ImFriendEntivity> mFrientEntivities;
    private FriendListClickListener mItemClickListener;
    private BlackListClickListener mBlackListClickListener;

    public BlackFriendAdpter(Context context, List<ImFriendEntivity> mFrientEntivities) {
        this.context = context;
        this.mFrientEntivities = mFrientEntivities;
    }
    public BlackFriendAdpter(Context context) {
        this.context = context;
    }

    public void refresh( List<ImFriendEntivity> mFrientEntivities) {
        this.mFrientEntivities = mFrientEntivities;
        notifyDataSetChanged();
    }

    public interface FriendListClickListener {
        void onAgreeNewFriendClick(View view, int position);
    }
    public interface BlackListClickListener {
        void onBlackListClickListener(View view, int position);
    }

    public void setItemClickListener(FriendListClickListener mItemClickListener) {
        this.mItemClickListener = mItemClickListener;
    }
    public void setItemRmClickListener(BlackListClickListener mBlackListClickListener) {
        this.mBlackListClickListener = mBlackListClickListener;
    }
    @Override
    public BlackFriendHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.child_item_layout, parent, false);
        return new BlackFriendHolder(view, mItemClickListener);
    }

    @Override
    public void onBindViewHolder(BlackFriendHolder holder, final int position) {
        holder.state_image.setVisibility(View.GONE);
        holder.text_pinyin.setVisibility(View.GONE);
        String name = mFrientEntivities.get(position).getRemark() ;
        if (null==name || "".equals(name))name = mFrientEntivities.get(position).getName();
        GlideUtils.loadCircleImage(context, mFrientEntivities.get(position).getHeadUrl(), holder.head_image);
        holder.name.setText(name);
        holder.item_detail.setText(mFrientEntivities.get(position).getSign());
        holder.delete.setVisibility(View.VISIBLE);

        holder.delete.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                mBlackListClickListener.onBlackListClickListener(view,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mFrientEntivities != null ? mFrientEntivities.size() : 0;
    }
}